package jkws

import "jkgo/jk/jklog"

const (
	serviceSelfname = "jkws"
	imgprocName     = "/jkimgproc"
	imgprocResponse = imgprocName + "/response"
)

func WSStart(addr string, port int, wsaddr string, wsport int) error {
	ws, err := newWSHandler(addr, port)
	if err != nil {
		jklog.L().Errorln(err)
		return err
	}
	iot, err := NewWSIoTHandler(wsaddr, wsport)
	if err != nil {
		jklog.L().Errorln(err)
		return err
	}

	ws.setIoT(iot)
	iot.setWS(ws)
	return nil
}


func WSStartTls(addr string, port int, wsaddr string, wsport int, cert, key string) error {
	ws, err := newWSHandlerTls(addr, port, cert, key)
	if err != nil {
		jklog.L().Errorln(err)
		return err
	}
	iot, err := NewWSIoTHandler(wsaddr, wsport)
	if err != nil {
		jklog.L().Errorln(err)
		return err
	}

	ws.setIoT(iot)
	iot.setWS(ws)
	return nil
}
